package _8GuoLvQi;

import _8GuoLvQi.impl.*;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * @Test: 过滤器模式 测试
 * @author: ZBoHang
 * @time: 2021/9/7 15:48
 */
class Test {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();

        persons.add(new Person("Robert", "Male", "Single"));
        persons.add(new Person("John", "Male", "Married"));
        persons.add(new Person("Laura", "Female", "Married"));
        persons.add(new Person("Diana", "Female", "Single"));
        persons.add(new Person("Mike", "Male", "Single"));
        persons.add(new Person("Bobby", "Male", "Single"));

        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        CriteriaSingle single = new CriteriaSingle();
        Criteria and = new AndCriteria(male, single);
        Criteria or = new OrCriteria(female, single);

        Consumer<Person> printPersonConsumer = person -> System.out.println("-->name " + person.getName());

        System.out.println("男------------------------------------------------------------------");
        List<Person> maleRes = male.meetCriteria(persons);
        maleRes.forEach(printPersonConsumer);
        System.out.println("女------------------------------------------------------------------");
        List<Person> femaleRes = female.meetCriteria(persons);
        femaleRes.forEach(printPersonConsumer);
        System.out.println("单------------------------------------------------------------------");
        List<Person> singleRes = single.meetCriteria(persons);
        singleRes.forEach(printPersonConsumer);
        System.out.println("男且单------------------------------------------------------------------");
        List<Person> andRes = and.meetCriteria(persons);
        andRes.forEach(printPersonConsumer);
        System.out.println("女或单------------------------------------------------------------------");
        List<Person> orRes = or.meetCriteria(persons);
        orRes.forEach(printPersonConsumer);
    }
}
